package csm.web.service.search;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.context.Context;

import csm.web.core.AjaxServletBase;
import csm.web.core.RequestHelper;
import csm.web.core.search.MashupItem;
import csm.web.core.search.MashupItemList;
import csm.web.core.search.SearchFacade;
import csm.web.core.search.SearchResultInfo;

public class MashupAjaxSearchServlet extends AjaxServletBase{
	/** */
	private static final long serialVersionUID = 4767099676413786831L;

	@Override
	public void populate(HttpServletRequest request,
			HttpServletResponse response, Context context) throws Exception {
		RequestHelper req = new RequestHelper(request);

		String mashupId = req.getParameter("mashup_id");
		MashupItem itm = MashupItemList.getInstance().getItem(mashupId);

		String viewPage = itm.getViewPage();
		context.put("PAGE", getThemaName(request) + "/" + viewPage);

		SearchResultInfo resultSet = SearchFacade.doMashupSearch(req, itm);
		context.put("MASHUP_SEARCH_RESULT_SET", resultSet);

		setJsonHeader(response, "{'result':'true'}");
		context.put("Result", true);


	}
}
